<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="taglib.jsp"%>
<!-- begin #header -->
<div id="header" class="header navbar navbar-default navbar-fixed-top">
    <!-- begin container-fluid -->
    <div class="container-fluid">
        <!-- begin mobile sidebar expand / collapse button -->
        <div class="navbar-header">
            <%--<a href="/" class="navbar-brand"><span class="navbar-logo"></span> 保险代理 </a>--%>
            <a href="/" class="navbar-brand" style="width: 325px;"><img src="/static/img/nav_logo.png" height="28" alt="logo图片" style="display: inline-block; margin-right: 5px;"><span>保险代理管理系统</span></a>
            <button type="button" class="navbar-toggle" data-click="sidebar-toggled">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
        </div>
        <!-- end mobile sidebar expand / collapse button -->

        <!-- begin header navigation right -->
        <ul class="nav navbar-nav navbar-right">
            <li class="dropdown navbar-user">
                <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown">
                    <img src="${ctx }/static/img/user-13.jpg" alt="" />
                    <span class="hidden-xs"> <shiro:principal property="realName" /> </span> <b class="caret"></b>
                </a>
                <ul class="dropdown-menu animated fadeInLeft">
                    <li class="arrow"></li>
                    <li><a href="#modal-checkPwd" data-toggle='modal'>修改密码</a></li>
                    <li class="divider"></li>
                    <li><a href="/logout">退出</a></li>
                </ul>
            </li>
        </ul>
        <!-- end header navigation right -->
    </div>
    <!-- end container-fluid -->
</div>

<!-- begin dialog -->
<div class="modal fade" id="modal-checkPwd" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <form role="form" action="/sysuser/modifyPassword"  class="form-horizontal" method="get" data-parsley-validate="true" id="dialogForm">
        <div class="modal-dialog" role="document" style="width: 400px;">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
                    <h4 class="modal-title" id="myModalLabel">修改密码</h4>
                </div>
                <div class="modal-body" style="position: relative;left: 18px;">
                    <div class="form-group">
                        <label  class="col-sm-3 control-label">您的账号：</label>
                         <div class="col-sm-8">
                          <p class="form-control-static">
		                        <shiro:principal property='realName' />
		                   </p>
	                    </div>
                    </div>
                    <div class="form-group">
                        <label  class="col-sm-3 control-label">原密码：</label>
                        <div class="col-sm-8">
                        	<input type="password" id="oldPassword" placeholder="" class="form-control" data-parsley-required="true" data-parsley-required-message="原密码不能为空" data-parsley-check="true" data-parsley-check-message="原密码输入错误">
                   		 </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">新密码：</label>
                        <div class="col-sm-8">
	                        <input type="password" id="password" placeholder="6-16位的字母、数字或符号组合" class="form-control" data-parsley-required="true" data-parsley-required-message="新的密码不能为空" data-parsley-length="[6,16]" data-parsley-length-message="请输入6-16字符以内" data-parsley-nzcheck="true" data-parsley-nzcheck-message="请输入字母、数字或符号两种组合">
	                   </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">确认新密码：</label>
                        <div class="col-sm-8">
	                        <input type="password" id="newPassword" placeholder="" class="form-control" data-parsley-required="true" data-parsley-required-message="确认密码不能为空" data-parsley-equalto="#password" data-parsley-equalto-message="两次输入结果不一致">
	                        <input type="hidden" name="newPassword" id="newPasswords">
	                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="submit" onclick="encryptInput()" class="btn btn-primary">保存</button>
                    <button type="button" onclick="tabModal()" class="btn btn-default" data-dismiss="modal">取消</button>
                </div>
            </div>
        </div>
    </form>
</div>
<script src="${ctx }/static/js/crypto-js.js"></script>
<script>


    function doSubmit() {
        $("#dialogForm").submit();
    }

     window.onload=function (){
    	window.ParsleyValidator.addValidator('check',function (oldPassword){
        	var result = true;
        	if(oldPassword!="" && oldPassword!=null){
                oldPasswords = encrypt(oldPassword);
        		$.ajax({
        			type:"post",
        			url:"/sysuser/checkOldPassword",
        			async:false,
        			data:{oldPassword:oldPasswords},
        			success:function (msg){
        				if(msg.success!=true){
        					result = false;
        				}
        			}
        		});
        	}
        	return result;
        },32);
    	
    	
    	window.Parsley.addValidator('nzcheck', function(value) {
    	    if(value!= ""){
    	    	return /^(?![0-9]+$)(?![a-zA-Z]+$)(?!([^(0-9a-zA-Z)]|[\(\)])+$)([^(0-9a-zA-Z)]|[\(\)]|[a-zA-Z]|[0-9])*$/.test(value)
    	    }
    	    return true;
    	},32);
    }
    
    function tabModal(){
    	$("#dialogForm").find("ul").addClass("hidden");
    	$("#dialogForm").find("input").val("").removeClass("parsley-error");
    	$("#dialogForm").find("input").val("").removeClass("parsley-success");
    	var tid = "<shiro:principal property='tid' />";
    	$.ajax({
    		type:"post",
    		url:"/sysuser/editLand",
    		data:{tid:tid},
    		success:function (msg){
    			
    		}
    	});
    } 
     
    //AES-128-CBC加密模式，key需要为16位，key和iv可以一样
    function encrypt(data) {
        var key  = CryptoJS.enc.Latin1.parse('0415f531c6e4e17b');
        var iv   = CryptoJS.enc.Latin1.parse('0415f531c6e4e17b');
        return CryptoJS.AES.encrypt(data, key, {iv:iv,mode:CryptoJS.mode.CBC,padding:CryptoJS.pad.ZeroPadding}).toString();
    }
    
    function encryptInput() {
        //获取用户输入值
        //var password1 = $("#oldPassword").val();
        //var password2 = $("#password").val();
        var password3 = $("#newPassword").val();
        //加密用户名和密码
        //oldPassword = encrypt(password1);
        //password = encrypt(password2);
        newPassword = encrypt(password3);
        //$("#oldPassword").val(oldPassword);
        //$("#password").val(password);
        $("#newPasswords").val(newPassword);
        $("#loginForm").submit();
    }
    
</script>